﻿using UnityEngine;
using Dict.DataModel;
namespace Room
{
    public class RoomSmallMap
    {
        protected GameObject miniMap;
        protected RoomBase room;
        public UI.MiniMapComponent miniMapComponent;

        public void Init(RoomBase room)
        {
            this.room = room;

            LoadMiniMap(0f);
        }

        public void ShowMiniMap()
        {
            if (miniMap != null)
            {
                miniMap.SetActive(true);
            }
        }

        public void HideMiniMap()
        {
            if (miniMap != null) miniMap.SetActive(false);
        }

        public virtual void Tick()
        {

        }

        protected virtual void LoadMiniMap(float angle)
        {
            //var temp = Resources.Load<GameObject>("prefab/MiniMap");
            //var inst = GameObject.Instantiate(temp);
            //var parent = RoomUIManager.Instance.transform;
            //inst.SetActive(true);
            //inst.transform.SetParent(parent);
            //inst.transform.localPosition = new Vector3(473, 240, 0);
            //inst.transform.localScale = Vector3.one;
            //inst.transform.localRotation = Quaternion.Euler(Vector3.zero);
            //SceneType st = room.GetSceneType();
            //if(st != SceneType.TOWN)
            //{
            //    inst.name = "MiniMap_" + room.GetSceneType().ToString();
            //}
            //miniMap = inst;
            miniMapComponent = UI.MiniMapComponent.Instance; //inst.GetComponent<UI.MiniMapComponent>();
            miniMapComponent.Init(angle, room);

        }

        public void SetData(TableScene ts)
        {
            if (ts != null)
                miniMapComponent.SetData(ts.minimapRes, (float)ts.miniMapOffsetX, (float)ts.miniMapOffsetY, 0, (float)ts.miniMapScale);
            else
                Debug.LogError("[error] mini map can't init this tableScene is null");
        }

        public void Unload()
        {
            miniMapComponent.UnloadResource();
        }

        public void SetData(TableCopyMission tcm)
        {
            TableScene ts = Dict.Blo.TableSceneBlo.GetSceneById(tcm.SceneName);
            miniMapComponent.SetData(ts.minimapRes, (float)ts.miniMapOffsetX, (float)ts.miniMapOffsetY, (float)tcm.CameraAngle, (float)ts.miniMapScale);
        }

        public void ResetData(string mapName, float offsetX, float offsetY, float angle, float scale)
        {
            miniMapComponent.SetData(mapName,offsetX,offsetY,angle,scale);
        }
       
    }
}
